package leetcode_201_300;

import java.util.HashMap;
import java.util.Map;

public class LeeCode_205 {
    public static void main(String[] args) {
        System.out.println(isIsomorphic("badc", "baba"));
    }
    private static boolean isIsomorphic(String s, String t) {
        int len = s.length();
        if (len != t.length())
            return false;
        Map<Character, Character> map = new HashMap<>();
        Map<Character, Character> map2 = new HashMap<>();
        for (int i = 0; i < len; i++) {
            char k = s.charAt(i);
            char v = t.charAt(i);
            if (!map.containsKey(k) && !map2.containsKey(v)){
                map.put(k, v);
                map2.put(v, k);
                continue;
            }

            if ((map.containsKey(k) && map.get(k) != v) || (map2.containsKey(v) && map2.get(v) != k))
                return false;
        }
        return true;
    }
}
